﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using ConfeccionesJR.BussinesLogic;
using ConfeccionesJR.Entites;


namespace ConfeccionesJR.UI
{
    public partial class frmCliente : Form
    {
        [Dependency]
        public IClienteBL cliBL { get; set; }

        public frmCliente()
        {
            InitializeComponent();
            this.BuildUp();
        }

        private void frmMttoCliente_Load(object sender, EventArgs e)
        {
            cLIENTEBindingSource.DataSource = cliBL.GetAllFromCliente();
        }

        private void BtnBuscar_Click(object sender, EventArgs e)
        {
            cLIENTEBindingSource.DataSource = cliBL.GetFromClienteByCriterio(razonSocialTextBox.Text);
        }

        private void BtnAdd_Click(object sender, EventArgs e)
        {
            frmMttoCliente frmCliente = new frmMttoCliente();
            frmCliente.AddCliente();
            frmCliente.ShowDialog();
            cLIENTEBindingSource.DataSource = cliBL.GetAllFromCliente();
        }   

        private void BtnUpdate_Click(object sender, EventArgs e)
        {
            CLIENTE currentCliente = cLIENTEBindingSource.Current as CLIENTE;
            if (currentCliente != null)
            {
                frmMttoCliente frmCliente = new frmMttoCliente();
                frmCliente.CurrentCliente = currentCliente;
                frmCliente.UpdateCliente();
                frmCliente.ShowDialog();
                cLIENTEBindingSource.DataSource = cliBL.GetAllFromCliente();
            }
            else
            {
                MessageBox.Show("Debe seleccionar un Cliente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void razonSocialTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                cLIENTEBindingSource.DataSource = cliBL.GetFromClienteByCriterio(razonSocialTextBox.Text);
            }

        }

        public CLIENTE CurrentCliente { get; set; }

        public bool Clien { get;  set; }

        private void cLIENTEDataGridView_DoubleClick(object sender, EventArgs e)
        {
            if (Clien == true)
            {
                CurrentCliente = cLIENTEBindingSource.Current as CLIENTE;
                Close();
            }
        }


    }
}
